import * as cardsService from '../service/cards';

export default {

  namespace: 'cards',

  state: {
    cardsList: [],
    statistic: {},
  },

  effects: {
    * queryList(_, sagaEffects) {
        const listData = [{
          name : 'umi',
          desc : '极快的类 Next.js 的 React 应用框架',
          url  : 'https://umijs.org'
        },
        {
          name : 'antd',
          desc : '一个服务于企业级产品的设计体系',
          url  : 'https://ant.design/index-cn'
        },
        {
          name : 'antd-pro',
          desc : '一个服务于企业级产品的设计体系',
          url  : 'https://ant.design/index-cn'
        }
        ];
        const { call, put } = sagaEffects;
        yield call(delay, 3000);
        yield put({ type: 'initList', payload: listData });
      }
    },

  reducers: {
    saveList(state, { payload: { cardsList } }) {
      return {
        ...state,
        cardsList,
      }
    },
    saveStatistic(state, { payload: { id, data } }) {
      return {
        ...state,
        statistic: {
          ...state.statistic,
          [id]: data,
        },
      }
    },
  },
};